<template>
  <div>
    <h1>商品管理</h1>
    <el-button type="success" round @click="addgoods()">增加按钮</el-button>
    <el-table :data="tableData" style="width: 100%">
<!--      <el-table-column prop="goodsId" label="商品编号" width="180"></el-table-column>-->
      <el-table-column prop="goodsName" label="商品名称" width="180"></el-table-column>
      <el-table-column prop="goodsStock" label="商品库存" width="180"></el-table-column>
      <el-table-column prop="goodsState" label="商品状态" width="180">
        <template slot-scope="scope">
          {{flag[scope.row.goodsState]}}
        </template>
      </el-table-column>
      <el-table-column prop="goodsQuantity" label="商品现有数量" width="180"></el-table-column>
      <el-table-column prop="goodsPrice" label="商品价格" width="180"></el-table-column>
      <!--    <el-table-column prop="deleted" label="日期" width="180"></el-table-column>-->
<!--      <el-table-column prop="createTime" label="创建日期" width="180"></el-table-column>-->
<!--      <el-table-column prop="updateTime" label="最后修改日期" width="180"></el-table-column>-->
      <el-table-column prop="storeId" label="商家编号" width="180"></el-table-column>
      <!--    <el-table-column label="操作">-->
      <!--      <template slot-scope="scope">-->
      <!--        <el-button size="mini" @click="handleEdit(scope.row.storeId)">显示商品</el-button>-->
      <!--        <el-button size="mini" type="danger" @click="handleDelete(scope.row.storeId)">删除</el-button>-->
      <!--      </template>-->
      <!--    </el-table-column>-->
    </el-table>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="goodslist.page"
        :page-sizes="[1, 3, 6, 9]"
        :page-size="goodslist.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="goodslist.total">
      </el-pagination>
    </div>
    <el-dialog title="添加数据" :visible.sync="dialogFormVisible">
      <el-form :model="goodslist">
        <el-form-item label="商品名称" :label-width="formLabelWidth">
          <el-input v-model="goodslist.goodsName" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="商品数量" :label-width="formLabelWidth">
          <el-input v-model="goodslist.goodsStock" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="商品价格" :label-width="formLabelWidth">
          <el-input v-model="goodslist.goodsPrice" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="addQuestion">确 定</el-button>
      </div>
    </el-dialog>
  </div>

</template>

<script>
    import axios from "axios";
    export default {
        name: "index",
      data(){
        return{
          tableData:[],
          goodslist:{page:1,size:3,total:0},
          flag:['待审核','审核通过','审核不通过','已上架','已下架'],
          dialogFormVisible: false,
          formLabelWidth: '120px',
          storeId:''
        }
      },
      methods:{
        getlist(){

          let storeId= sessionStorage.getItem("storeId")
          var us= new FormData();
          us.append("page",this.goodslist.page)
          us.append("size",this.goodslist.size)
          us.append("total",this.goodslist.total)
          us.append("storeId",storeId)

          axios.post("http://localhost:7000/shop/store/storegoodslist",us,this.goodslist).then(res=>{
            console.log(res)
            this.goodslist.total=res.data.data.total
            this.tableData=res.data.data.records
          })
        },
        handleSizeChange(val) {
          this.goodslist.size=val
          console.log(`每页 ${val} 条`);
          this.getlist()
        },
        handleCurrentChange(val) {
          this.goodslist.page=val
          console.log(`当前页: ${val}`);
          this.getlist()
        },
        addgoods(){
          let storeId= sessionStorage.getItem("storeId")
          console.log(storeId)
          this.storeId=storeId
          this.dialogFormVisible = true
        },
        addQuestion(){
          this.dialogFormVisible = false
          let storeId= sessionStorage.getItem("storeId")
          // var us= new FormData();
          // us.append("storeId",storeId)
          axios.post("http://localhost:7000/shop/store/storegoodsadd?storeId="+storeId,this.goodslist).then((res) => {
            this.dialogFormVisible = false
            this.getlist()
            console.log(res)
          })
        }
        // handleEdit(storeId) {
        //   console.log(storeId);
        //   this.$router.push("goods")
        // },
        // handleDelete(storeId) {
        //   console.log(storeId);
        // }
      },
      mounted() {
        this.getlist()
      }
    }
</script>

<style scoped>

</style>
